<?php
/**
 * @Name: Redis.php
 * @Author: yashuai
 */

namespace App\Http\Services\Redis;

use App\Http\Services\BaseServices;

class RedisServices extends BaseServices
{

    private static $redis = [];

    public static function connect($db = 0)
    {
        if (isset(self::$redis[$db])) {
            self::createConnect($db);
        }
        return self::$redis[$db];
    }


    private static function createConnect($db = 0)
    {
        self::$redis[$db] = new \Redis();
        self::$redis[$db]->connect(env('redis.host', '127.0.0.1'), env('redis.port', '6379'));
        self::$redis[$db]->auth(env('redis.auth'));
        self::$redis[$db]->select($db);
    }

}
